<template>
  <div>
    <h3>听歌列表</h3>
    {{ m_list }}

     
    <div v-for="(item,i) in m_list " :key="i">
        <router-link :to="({name:'Dealt',params:{id:item.id}})">  
           <span  @click="addH(i+1)">{{ item.name }}</span> 
       </router-link>
    </div>
   
    
    <el-button @click="ho">展示历史记录页</el-button>
  </div>
</template>

<script>
import axios from 'axios'
export default {
    data(){
        return{
            m_list:[],
        }
    },
    mounted(){
        this.getMusic()
    },
    methods:{
        ho(){
            this.$router.push('/hosrroy')
        },
        getMusic(){
            axios.get('http://127.0.0.1:8000/user/music/')
            .then(resp=>{
                console.log(resp);
                this.m_list=resp.data.data
            })
            .catch(err=>{
                console.log(err);
            })
            
        },
        addH(id){
            axios.post('http://127.0.0.1:8000/user/hostroy/',{
                id:id,
                token:localStorage.getItem('token')
            })
            .then(resp=>{
                console.log(resp);
                // this.$router.push({name:'Dealt',params:{id:id}})
            })
            .catch(err=>{
                console.log(err);
            })
        },
    }
}
</script>

<style>

</style>